package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YyAppointmentTime;
import com.ruoyi.system.service.IYyAppointmentTimeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预约时间段Controller
 * 
 * @author ruoyi
 * @date 2025-03-25
 */
@Controller
@RequestMapping("/system/time")
public class YyAppointmentTimeController extends BaseController
{
    private String prefix = "system/time";

    @Autowired
    private IYyAppointmentTimeService yyAppointmentTimeService;

    @RequiresPermissions("system:time:view")
    @GetMapping()
    public String time()
    {
        return prefix + "/time";
    }

    /**
     * 查询预约时间段列表
     */
    @RequiresPermissions("system:time:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YyAppointmentTime yyAppointmentTime)
    {
        startPage();
        List<YyAppointmentTime> list = yyAppointmentTimeService.selectYyAppointmentTimeList(yyAppointmentTime);
        return getDataTable(list);
    }

    /**
     * 导出预约时间段列表
     */
    @RequiresPermissions("system:time:export")
    @Log(title = "预约时间段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YyAppointmentTime yyAppointmentTime)
    {
        List<YyAppointmentTime> list = yyAppointmentTimeService.selectYyAppointmentTimeList(yyAppointmentTime);
        ExcelUtil<YyAppointmentTime> util = new ExcelUtil<YyAppointmentTime>(YyAppointmentTime.class);
        return util.exportExcel(list, "预约时间段数据");
    }

    /**
     * 新增预约时间段
     */
    @RequiresPermissions("system:time:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存预约时间段
     */
    @RequiresPermissions("system:time:add")
    @Log(title = "预约时间段", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YyAppointmentTime yyAppointmentTime)
    {
        return toAjax(yyAppointmentTimeService.insertYyAppointmentTime(yyAppointmentTime));
    }

    /**
     * 修改预约时间段
     */
    @RequiresPermissions("system:time:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        YyAppointmentTime yyAppointmentTime = yyAppointmentTimeService.selectYyAppointmentTimeById(id);
        mmap.put("yyAppointmentTime", yyAppointmentTime);
        return prefix + "/edit";
    }

    /**
     * 修改保存预约时间段
     */
    @RequiresPermissions("system:time:edit")
    @Log(title = "预约时间段", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YyAppointmentTime yyAppointmentTime)
    {
        return toAjax(yyAppointmentTimeService.updateYyAppointmentTime(yyAppointmentTime));
    }

    /**
     * 删除预约时间段
     */
    @RequiresPermissions("system:time:remove")
    @Log(title = "预约时间段", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(yyAppointmentTimeService.deleteYyAppointmentTimeByIds(ids));
    }
}
